package com.diao.myhub.asserts;

import com.diao.myhub.exception.CustomizeError;
import com.diao.myhub.exception.CustomizeException;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

public class ServiceAsserts {
    public static void notBlank(String str, String message) {
        if (!StringUtils.hasText(str)) {
            throw new CustomizeException(message, 500);
        }
    }

    public static void notBlank(String str, CustomizeError e) {
        if (!StringUtils.hasText(str)) {
            throw new CustomizeException(e);
        }
    }

    public static void notEmpty(Object obj, String message) {
        if (ObjectUtils.isEmpty(obj)) {
            throw new CustomizeException(message, 500);
        }
    }

    public static void notEmpty(Object obj, CustomizeError e) {
        if (ObjectUtils.isEmpty(obj)) {
            throw new CustomizeException(e);
        }
    }

    public static void notNull(Object obj, String message) {
        if (ObjectUtils.isEmpty(obj)) {
            throw new CustomizeException(message, 500);
        }
    }

    public static void notNull(Object obj, CustomizeError e) {
        if (ObjectUtils.isEmpty(obj)) {
            throw new CustomizeException(e);
        }
    }

    public static void isTrue(boolean res, String message) {
        if (!res) {
            throw new CustomizeException(message, 500);
        }
    }

    public static void isTrue(boolean res, CustomizeError e) {
        if (!res) {
            throw new CustomizeException(e);
        }
    }
}
